package com.huike.business.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 *
 * @author wgl
 * @date 2021-04-28
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {
    @Autowired
    private TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;

    @Autowired
    private TbBusinessMapper tbBusinessMapper;

    @Override
    public int insertTbBusinessTrackRecord(BusinessTrackVo businessTrackVo) {
        // 修改商机
        TbBusiness business = new TbBusiness();
        BeanUtil.copyProperties(businessTrackVo, business, "id");
        business.setId(businessTrackVo.getBusinessId());
        business.setCreateBy(SecurityUtils.getUsername());
        business.setCreateTime(DateUtils.getNowDate());
        tbBusinessMapper.updateTbBusiness(business);

        // 添加商机跟进记录
        TbBusinessTrackRecord tbBusinessTrackRecord = new TbBusinessTrackRecord();
        BeanUtil.copyProperties(businessTrackVo, tbBusinessTrackRecord);
        tbBusinessTrackRecord.setCreateBy(SecurityUtils.getUsername());
        tbBusinessTrackRecord.setCreateTime(DateUtils.getNowDate());
        tbBusinessTrackRecord.setUpdateTime(DateUtils.getNowDate());

        return tbBusinessTrackRecordMapper.insertTbBusinessTrackRecord(tbBusinessTrackRecord);
    }

    @Override
    public AjaxResult selectTbBusinessTrackRecordListById(Long id) {
        List<TbBusinessTrackRecord> businessTrackRecordList = tbBusinessTrackRecordMapper.selectTbBusinessTrackRecordListById(id);
        return AjaxResult.success(businessTrackRecordList);
    }
}
